/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
  \file dataDistribution.h
  \brief header file for XML parser

  \author Jack Elston
  $Date: 2006/10/25 13:34:45 $
  */

#ifndef __DATADISTRIBUTION_H
#define __DATADISTRIBUTION_H

#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>

#include "String.h"
#include "command.h"
#include "queue.h"
#include "type_defs.h"
#include "threadedPipe.h"
#include "shmStruct.h"
#include "interface.h"

#include "fileLog.h"

/*<-------Defines--------->*/
/*! \brief seconds between capabilites transmission. */
#define CAPABILITES_PERIOD 10
#define MAX_INTERFACES 16 
/*<------End Defines------>*/

typedef struct _InterfaceRecord_t{
	Interface * pointer;
	int RxFD;
	int TxFD;
	_InterfaceRecord_t () { pointer = NULL; RxFD = TxFD = -1;}
} InterfaceRecord_t;

/************************************************************\
  |                    Data_Distribution                        |
  \************************************************************/
/*!
  \class Data_Distribution
  \brief reads XML data from a fifo, parses it and places it
  into an appropriate outgoing fifo
  \todo switch statement need to be implemented to handle different types of incomming data
  \todo switch statement need to be implemented to handle different types of tasks (other than "Loiter").
  \todo waypoint.part0.Alt=1800 is statically set
  \todo waypoint.part1.OrbitRad=50 is statically set
  \todo waypoint.part1.Next is set to 0 - This is a hack to make piccolo integration work (Since the piccolo requries at least two points to make a flightplan).
  */
class Data_Distribution : public ThreadedPipe
{
	private:
		InterfaceRecord_t interfaces[MAX_INTERFACES];
		int num_interfaces;

		TimeStamp last_cap_tx;
		bool transmit_cap;

		FileLog comm_log;

	public:
		Data_Distribution(String name, String logDir = "./");
		~Data_Distribution();

		void update();
		void registerInterface(Interface * an_interface);
		void parse(const Command &cmd, in_addr address);
};

#endif //define
